layui.define(['form', 'laydate', 'table', 'buyHouseSubsidiesApi'], function (exports) {
    var form = layui.form;
    var buyHouseSubsidiesApi = layui.buyHouseSubsidiesApi;
    var index = layui.index;
    var view = {
        init: function () {
            Lib.initGenrealForm($("#updateForm"), form);
            this.initSubmit();
        },
        initSubmit: function () {
            $("#updateButton").click(function () {
                form.on('submit(form)', function () {
                    var roomType = Common.fileRequire("#roomTypeDataList");
                    if (roomType) {
                        Common.alert("房产证原件扫描件附件必须上传");
                    } else {
                        buyHouseSubsidiesApi.updateBuyHouseSubsidies($('#updateForm'), function () {
                            parent.window.dataReload();
                            Common.info("更新成功");
                            Lib.closeFrame();
                        });
                    }
                });
            });
            $("#updateButton-cancel").click(function () {
                Lib.closeFrame();
            });
            $("#updateButton-declare").click(function () {

                    var isEmpty = Common.fileRequire("#roomTypeDataList");
                    if (isEmpty) {
                        Common.alert("房产证原件扫描件附件必须上传");
                    } else {
                        Common.openConfirm("确认申报?", function () {
                            buyHouseSubsidiesApi.updateAndDeclareBuyHouseSubsidies($('#updateForm'), function () {
                                parent.window.dataReload();
                                Common.info("申报成功");
                                Lib.closeFrame();
                            });
                        }, null)
                    }
                });
                $("#acceptance-termination").click(function () {
                    form.on('submit(form)', function () {
                        Common.openConfirm("确认终止?", function () {
                            var callback = function () {
                                parent.window.dataReload();
                                Common.info("终止成功");
                                Lib.closeFrame();
                            };
                            Lib.submitForm("/cms/buyHouseSubsidies/terminal.json", $('#updateForm'), {}, callback);
                        }, null)
                    });


                });
                $("#acceptance-return").click(function () {

                    form.on('submit(form)', function () {
                        Common.openConfirm("确认退回?", function () {
                            var callback = function () {
                                parent.window.dataReload();
                                Common.info("退回成功");
                                Lib.closeFrame();
                            };
                            Lib.submitForm("/cms/buyHouseSubsidies/back.json", $('#updateForm'), {}, callback);
                        }, null)
                    });

                });
                $("#acceptance-adopt").click(function () {

                    if (document.getElementById("handlingSuggestion").value.trim() == '') {
                        $("#handlingSuggestion").val("通过");
                    }

                    var f = function () {
                        form.on('submit(form)', function () {
                            Common.openConfirm("确认通过?", function () {
                                var callback = function () {
                                    parent.window.dataReload();
                                    Common.info("通过成功");
                                    Lib.closeFrame();
                                };
                                Lib.submitForm("/cms/buyHouseSubsidies/pass.json", $('#updateForm'), {}, callback);
                            }, null)
                        });
                    }
                    Common.validAll(f);

                });
            }

        }
        exports('edit', view
)
    ;

});